/**
 * Copyright (c) 2012 Fujian FUNO Mobile Communication Technology Co., Ltd.
 * All rights reserved by FUNO.
 */
package com.funo.aspect;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.funo.exception.RecoverableException;
import com.funo.util.LogUtils;

/**
 * 用于做方法开始和方法结束的日志,并记录输入参数,和返回参数
 * 
 * @version V1.0
 * @author linzhiwei
 * 
 */
@Component("serviceLogAspectj")
@Aspect
public class ServiceLogAspectj extends BaseLogAroundAspectj{
	
	private final Log log = LogFactory.getLog(ServiceLogAspectj.class); 

	@Around("execution(* com.funo.service.*.*.*())")
	public Object servicePointcutter(ProceedingJoinPoint pjp) throws Throwable {
		long start = System.currentTimeMillis();
		Object result;
		try {
			result = proceed(pjp);
		} catch (Exception e) {
			if(e instanceof RecoverableException){
				log.warn(e.getMessage(),e);
			}else{
				log.error(e.getMessage(), e);
			}
			throw e;
		}
		LogUtils.info(log, "service执行时间为:{}", (System.currentTimeMillis() - start));
		return result;
	}


}
